package controller.listeners.mainWindow;


import model.MainWindowModel;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;

import business.ViewLogger;
import view.MainWindowView;
import view.ViewUtils;

/**
 * Controlador para la caja de texto del corp personalizado
 * @author 53385255R
 *
 */
public class MessageKeyDownListener implements Listener {

	private MainWindowView _view;
	private MainWindowModel _model;
	
			/**
			 * @param view
			 * @param model
			 */
			public MessageKeyDownListener(MainWindowView view,MainWindowModel model) {
				this._model = model;
				this._view = view;
			}
			
			 /**
			 * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
			 */
			@Override
			public void handleEvent(Event event) {
					if (event.stateMask == SWT.CTRL && (event.keyCode == 67 || event.keyCode == 99 || event.keyCode == 119))//99 es la 'c',pero no se porque no la pilla. Pongo la W, 119
	            		_view.messageCopy();
					else if (event.stateMask == SWT.CTRL && (event.keyCode == 103 || event.keyCode == 71)) //103 es la 'g' y 71 la G
				         ViewUtils.getInstance().openGoogleSearch(_view.getSelectionText());
		            else if  (event.keyCode == SWT.F1) {
						
		            	String help = "\n\nACCIONES PARA LA CONSOLA DE MENSAJES\n- Ctrl + 'g': busca en google el texto seleccionado.";
		            	
						ViewLogger.getInstance().info(help);
						ViewUtils.getInstance().informationMessage("Ayuda filtrado", help,true);
					}
		        }
		}